import easyquotation
import json
import asyncio

quotationQq = easyquotation.use('sina')
fixed_codes = ["sh000001", "sz399001"]


async def fetch_stock_data():
    while True:
        stock_data = quotationQq.stocks(fixed_codes, prefix=True)
        await asyncio.sleep(5)  # 每5秒钟更新一次数据

        yield json.dumps(stock_data)

# async def fetch_stock_data(codes):
#     while True:
#         all_codes = list(set(fixed_codes + codes))
#         stock_data = quotationQq.stocks(all_codes, prefix=True)
#         await asyncio.sleep(5)  # 每5秒钟更新一次数据

#         yield json.dumps(stock_data)
